****************co2 and financial depth************
//set the data path
cd E:\data\合作研究\金融减排\data
use co2_data,clear  //load the data





gen fdepth2= fdepth^2



**************
bysort province: egen energy_d=mean(fossild1)

tabstat energy_d, stat(p50)

gen energy_dum=0
replace energy_dum=1 if energy_d>0.721395

//set the labels of the variables
label var per_co2 "CO2 emissions per capital (tons of standard coal)"
label var fdepth "Financial depth (%)"
label var tech "Technological innovation"
label var env_regul "Environment regulation"
label var energy "Energy consumption (tons of coal per people)"
label var l_per_gdp "The log of real GDP per capital (constant 1999 price)"
label var l_population "The log of population (people per sq. km of land area)"
label var stru_2 "Proportion of secondary industry  (%)"
label var SW  "Industrial solid waste output per capital"
label var gdp_a  "The growth rate of real GDP (constant 1999 price)"
label var internet_use  "Internet penetration"
label var struct_s  "Industrial structure (%)"
label var cpi  "Consumer Price Index"
label var fdepth2  "The square of financial depth"
label var l_fdi "The log of FDI (constant 1999 price)"
label var fossild1 "Fossil energy dependence"

gen l_trade=ln(trade)


//set the panel data
egen id=group(province)
xtset id year
gen fdepth3=fdepth^3


by id: ipolate internet_use year,gen(internet_use1) epolate
replace internet_use=internet_use1
*****************************data description**********************
sum per_co2 SW fdepth l_per_gdp tech struct_s gdp_a cpi l_population l_fdi internet_use  env_regul    fossild1  

des per_co2 SW fdepth l_per_gdp tech struct_s gdp_a cpi l_population l_fdi internet_use  env_regul    fossild1 


//statisitcal anlysis
 xtunitroot fisher per_co2, dfuller lags(3) drift
 xtunitroot fisher fdepth, dfuller lags(1) drift
collin  fdepth l_per_gdp   tech struct_s   gdp_a cpi l_population l_fdi internet_use  env_regul  
des fdepth l_per_gdp   tech struct_s   gdp_a cpi l_population l_fdi internet_use  env_regul 


//besic result
reg per_co2 fdepth   gdp_a cpi l_population  internet_use  env_regul l_fdi tech     
est store reg1
xtgls per_co2  fdepth   gdp_a cpi l_population  internet_use  env_regul l_fdi tech   i.year, panels(hetero)
est store reg2
xtreg per_co2  fdepth   gdp_a cpi l_population  internet_use  env_regul l_fdi tech   ,fe
est store reg3
xtreg per_co2  fdepth   gdp_a cpi l_population  internet_use  env_regul l_fdi tech  i.year,re
est store reg4
xtreg per_co2  fdepth  fdepth2  gdp_a cpi l_population  internet_use  env_regul l_fdi tech  i.year ,fe
est store reg5
esttab reg1 reg2 reg3 reg4 reg5 , cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fdepth  fdepth2   gdp_a cpi l_population l_fdi internet_use  env_regul  tech   _cons) ///
legend label varwidth(60) varlabels(_cons Constant) mtitles("ols" "FGLS" "FE" "RE" "FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  

hausman reg3 reg4,sigmamore


//Moderating Effect

xtreg per_co2  fdepth l_per_gdp   tech struct_s   gdp_a cpi l_population l_fdi internet_use  env_regul   ,fe
est store reg1

xtreg l_per_gdp  fdepth        gdp_a cpi l_population l_fdi internet_use  env_regul  ,fe
est store reg3
xtreg tech  fdepth        gdp_a cpi l_population l_fdi internet_use  env_regul  ,fe
est store reg4
xtreg struct_s  fdepth      gdp_a cpi l_population l_fdi internet_use  env_regul  ,fe
est store reg5
esttab   reg3 reg4 reg5 reg1, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fdepth l_per_gdp  gdp_a cpi l_population l_fdi internet_use  env_regul  tech struct_s _cons) ///
legend label varwidth(60) varlabels(_cons Constant) mtitles("per_co2"  "l_per_gdp" "tech" "struc_third") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  


*********************************************
hist fossild1,bin(40) ylabel(,nogrid)



//Economical scale effect
tabstat fossild1, stat(p50 mean)

gen dum_energy=0
replace dum_energy=1 if fossild1>=.7319233
gen gdp_dum=l_per_gdp*dum_energy
gen   f_dum=fdepth*dum_energy


xtreg per_co2  fdepth l_per_gdp      gdp_a cpi l_population l_fdi internet_use  env_regul   if dum_energy==0,fe
est store reg1
xtreg per_co2  fdepth l_per_gdp      gdp_a cpi l_population l_fdi internet_use  env_regul  if dum_energy==1,fe
est store reg2
xtreg per_co2  fdepth l_per_gdp  gdp_dum  dum_energy   gdp_a cpi l_population l_fdi internet_use  env_regul  ,fe
est store reg3

xtreg l_per_gdp  fdepth        gdp_a cpi l_population l_fdi internet_use  env_regul  if dum_energy==0,fe
est store reg4

xtreg l_per_gdp  fdepth        gdp_a cpi l_population l_fdi internet_use  env_regul  if dum_energy==1,fe
est store reg5
xtreg l_per_gdp  fdepth   f_dum   dum_energy gdp_a cpi l_population l_fdi internet_use  env_regul  ,fe
est store reg6
esttab reg1 reg2 reg3 reg4 reg5 reg6, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep ( fdepth l_per_gdp gdp_dum dum_energy  f_dum   _cons) ///
legend label varwidth(50) varlabels(_cons Constant) mtitles("Low" "High" "All" "Low" "High" "All") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  



//Technological innovation effect
gen tech_dum=-tech*dum_energy
replace f_dum=fdepth*dum_energy

xtreg per_co2  fdepth   tech    l_per_gdp    struct_s    gdp_a cpi l_population l_fdi internet_use  env_regul   if dum_energy==0,fe
est store reg1
xtreg per_co2  fdepth   tech   l_per_gdp    struct_s    gdp_a cpi l_population l_fdi internet_use  env_regul   if dum_energy==1,fe
est store reg2 

xtreg per_co2  fdepth tech_dum   tech  dum_energy l_per_gdp  struct_s    gdp_a cpi l_population l_fdi internet_use  env_regul ,fe
est store reg3

xtreg tech  fdepth         gdp_a cpi l_population l_fdi internet_use  env_regul  if dum_energy==0,fe
est store reg4
xtreg tech  fdepth       gdp_a cpi l_population l_fdi internet_use  env_regul  if dum_energy==1,fe
est store reg5
xtreg tech  fdepth  f_dum  dum_energy  gdp_a cpi l_population l_fdi internet_use  env_regul ,fe
est store reg6

esttab reg1 reg2 reg3 reg4 reg5 reg6, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fdepth   tech  tech_dum f_dum dum_energy  _cons ) ///
legend label varwidth(50) varlabels(_cons Constant) mtitles("Low" "High" "All" "Low" "High" "All") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  

// Industrial structure upgrade effect
gen struc_third_dum=-struct_s*dum_energy
replace f_dum=fdepth*dum_energy
xtreg per_co2  fdepth   struct_s    gdp_a  cpi l_population l_fdi internet_use  env_regul   if dum_energy==0,fe
est store reg1
xtreg per_co2  fdepth   struct_s   gdp_a  cpi l_population l_fdi internet_use  env_regul   if dum_energy==1,fe
est store reg2
xtreg per_co2  fdepth struct_s  dum_energy  struc_third_dum     gdp_a  cpi l_population l_fdi internet_use  env_regul  ,fe
est store reg3

xtreg struct_s  fdepth         gdp_a cpi l_population l_fdi internet_use  env_regul  if dum_energy==0,fe
est store reg4
xtreg struct_s  fdepth       gdp_a cpi l_population l_fdi internet_use  env_regul  if dum_energy==1,fe
est store reg5
xtreg struct_s  fdepth  f_dum  dum_energy  gdp_a cpi l_population l_fdi internet_use  env_regul stru_2 ,fe
est store reg6

esttab reg1 reg2 reg3 reg4 reg5 reg6, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fdepth   struct_s  struc_third_dum f_dum  dum_energy _cons) ///
legend label varwidth(50) varlabels(_cons Constant) mtitles("Low" "High" "All" "Low" "High" "All") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  





*****************************************robust test********************

xtreg SW  fdepth   gdp_a cpi l_population l_fdi internet_use  env_regul  tech   ,fe
est store reg1

xtreg SW  fdepth  fdepth2 gdp_a cpi l_population l_fdi internet_use  env_regul  tech   ,fe
est store reg2
xtivreg SW  (fdepth= fdepth_loan L.fdepth)  gdp_a cpi l_population l_fdi internet_use  env_regul tech   ,fe
xtoverid
dmexogxt
est store reg3

//mediting effect
xtreg SW  fdepth l_per_gdp   tech struct_s   gdp_a cpi l_population l_fdi internet_use  env_regul  ,fe
est store reg7

xtreg l_per_gdp  fdepth        gdp_a cpi l_population l_fdi internet_use  env_regul ,fe
est store reg4
xtreg tech  fdepth        gdp_a cpi l_population l_fdi internet_use  env_regul ,fe
est store reg5
xtreg struct_s  fdepth      gdp_a cpi l_population l_fdi internet_use  env_regul ,fe
est store reg6

esttab reg1 reg2 reg3 reg4 reg5 reg6 reg7, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fdepth l_per_gdp  struct_s tech  fdepth2 _cons) ///
legend label varwidth(40) varlabels(_cons Constant) mtitles("ols" "FGLS" "FE" "RE" "FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  /*table 3*/









*******
xtreg SW  fdepth_inv l_per_gdp   tech struct_s   gdp_a cpi l_population l_fdi internet_use   env_regul stru_2 ,fe
est store reg1

xtreg l_per_gdp  fdepth_inv        gdp_a cpi l_population l_fdi internet_use  env_regul stru_2,fe
est store reg3
xtreg tech  fdepth_inv        gdp_a cpi l_population l_fdi internet_use  env_regul stru_2,fe
est store reg4
xtreg struct_s  fdepth_inv      gdp_a cpi l_population l_fdi internet_use  env_regul stru_2,fe
est store reg5

esttab reg1  reg3 reg4 reg5 , cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fdepth_inv l_per_gdp  gdp_a cpi l_population l_fdi internet_use  env_regul struct_s tech stru_2 _cons) ///
legend label varwidth(50) varlabels(_cons Constant) mtitles("ols" "FGLS" "FE" "RE" "FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  /*table 3*/






